import { useOption } from '@/stores/option';
const OPTION = useOption();
const util = {
  getVector(Svg, origins) {
    const { width, space, max, length } = OPTION;
    const ratio = max / length;
    console.log(ratio);

    Svg.attr({ width: (width + space) * length, height: max + 20 });
    return origins.map((n, i) => {
      const r = Svg.rect(0, max - n * ratio, width, n * ratio, 4, 4).attr({
        fill: OPTION.color.processing,
      });
      const g = Svg.g(r, Svg.text(width / 2, max + 15, n));
      g.attr({ transform: `translate(${(width + space) * i})` });
      return { i, n, r, g };
    });
  },
  exchange(left, right) {
    const l = left.g.matrix.e,
      r = right.g.matrix.e;
    left.g.animate({ transform: `translate(${r})` }, OPTION.speed * 0.8);
    right.g.animate({ transform: `translate(${l})` }, OPTION.speed * 0.8);
  },
};

export default util;
